import { IParam, IReturn, IOption, IAttr } from '../../types/normal';

/**
 * 拼接 Params 列表的 Markdown 内容
 */
export function splicParamsContent(params: Array<IParam>) {
    const text = params.reduce((acc, cur, i) => {
        if (cur.name) acc += cur.name;
        if (cur.type && cur.type.length) acc += ` { ${cur.type.join(' \\| ')} }`;
        if (cur.desp) acc += ` ${cur.desp}`;
        if (i !== params.length - 1) acc += '<br>';
        return acc;
    }, '');

    return text.trim() || '-';
}

/**
 * 拼接 Options 列表的 Markdown 内容
 */
export function splicOptionsContent(options: Array<IOption>) {
    return options.reduce((acc, cur, i) => {
        if (cur.name) {
            acc += cur.name;
            if (cur.desp) acc += ` ${cur.desp}`;
        } else {
            acc += '-';
        }
        if (i !== options.length - 1) acc += '<br>';
        return acc;
    }, '');
}

/**
 * 拼接 Returns 列表的 Markdown 内容
 */
export function splicReturnsContent(returns: IReturn) {
    let str = '';
    if (returns.type && returns.type.length) str += `{ ${returns.type.join(' \\| ')} }`;
    if (returns.desp) str += ` ${returns.desp}`;
    return str.trim();
}

/**
 * 拼接 Slot 属性的 Markdown 内容
 */
export function splicSlotAttrsContent(attrs: Array<IAttr>) {
    return attrs.reduce((acc, cur, i) => {
        if (cur.name) {
            acc += cur.name;
        } else {
            acc += '-';
        }
        if (i !== attrs.length - 1) acc += '<br>';
        return acc;
    }, '');
}
